package com.doubi.service;

import com.doubi.model.sys.THelpCenter;
import com.doubi.modelvo.sys.THelpCenterVo;
import com.doubi.utils.DataUtil;
import com.doubi.utils.JsonUtils;
import com.doubi.vo.AppUiModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApiHelpCenterService {
    @Autowired
    private HelpCenterService helpCenterService;

    /**
     * MrDoubi
     * 2020年3月10日 14:48:43
     * 获取帮助中心信息
     * @return list
     */
    public AppUiModel<List<THelpCenterVo>> getHelpCenterList(int type){
        return new AppUiModel<>(JsonUtils.copyList(helpCenterService.getHelpCenterList(type), THelpCenterVo.class));
    }

    /**
     * MrDoubi
     * 2020年3月10日 14:59:40
     * 获取帮助中心详情
     * @param oid 唯一标识
     * @return model
     */
    public AppUiModel<THelpCenterVo> getHelpCenterDetails(String oid){
        if(DataUtil.isEmpty(oid)){
            return new AppUiModel<>(400,"请选择一个帮助中心查看！");
        }
        THelpCenter center = helpCenterService.getById(oid);
        if(DataUtil.isEmpty(center)){
            return new AppUiModel<>(400,"帮助中心内容不存在！");
        }
        THelpCenterVo helpCenterVo = new THelpCenterVo();
        BeanUtils.copyProperties(center,helpCenterVo);
        return new AppUiModel<>(helpCenterVo);
    }
}
